package com.pro.control;

import com.pro.dao.ConversationMapper;
import com.pro.entity.JsonData;
import com.pro.service.ConversationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: ConversationController
 * @Author: 笑笑
 * @DATE: 2021/11/16
 * @TIME: 下午 08:40
 */
@RestController
@RequestMapping("/Conversation")
public class ConversationController {
    @Autowired
    private ConversationService conversationService;

    //查看所有数据展示表
    @RequestMapping("/getTable")
    public JsonData getTable() {
        List<ConversationMapper> table = conversationService.getTable();
        return table.size() > 0 ? JsonData.buildSuccess(table) : JsonData.buildError("没有查到表");
    }

    //根据id查看会话记录
    @RequestMapping("/getRecord")
    public JsonData getRecord(Integer id) throws Exception {
        ConversationMapper record = conversationService.getRecord(id);
        return record != null ? JsonData.buildSuccess(record) : JsonData.buildSuccess("没有查询到会话记录");
    }

    //根据id删除会话记录
    @RequestMapping("/deleteRecord")
    public JsonData deleteRecord(Integer id) throws Exception {
        Boolean aBoolean = conversationService.deleteRecord(id);
        return aBoolean ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("添加失败");
    }
}
